import registnet.dao.CourseOffering;
import registnet.dao.CourseOfferingPeer;
import registnet.dao.UnitPeer;


import resources.Constants;


/* [start] 	initializes gui variables */
String _office = session.getAttribute("_office");

String _course_offering = "Course Offering";

/* [end] */


private class CourseOfferingRenderer implements RowRenderer  {
	public void render(Row row, java.lang.Object data) {
		new Label(data[0]).setParent(row);
		new Label(data[1]).setParent(row);
		new Label(data[2]).setParent(row);
		new Label(data[3]).setParent(row);
		new Label(data[4]).setParent(row);
		new Label(data[5]).setParent(row);
		new Label(data[6]).setParent(row);
	}
}

void retrieveCourseOfferings(){
	try{
		Integer semesterValue = Constants.MAP_SEMESTER_KEY.get(semester.getSelectedItem().getLabel());
			Integer yearValue;
			if (semesterValue == Constants.MAP_SEMESTER_KEY.get(Constants.SUMMER))
				yearValue = Integer.parseInt(year2.value);
			else
				yearValue = Integer.parseInt(year1.value);
		
		List courseOfferings;
		
		if(_user_type.equals(Constants.REGISTRAR)){
			courseOfferings = new CourseOfferingPeer().getCourseOfferingsByUnit(new  UnitPeer().getUnitId("OUR"), semesterValue, yearValue);
		}
		else if (_user_type.equals(Constants.UNIT)){
			courseOfferings = new CourseOfferingPeer().getCourseOfferingsByUnit(new  UnitPeer().getUnitId(_office), semesterValue, yearValue);
		}
		
		String[][] listModel = new String[courseOfferings.size()][7];
	
		for(i = 0; i < courseOfferings.size(); i++){
			CourseOffering courseOffering = courseOfferings.get(i);
			listModel[i][0] = courseOffering.getCourse().getCourseCode();
			listModel[i][1] = courseOffering.getCourseOfferingName();
			if(courseOffering.getLaboratoryDay() != null && courseOffering.getLaboratoryDay().length() != 0){
				listModel[i][2] = courseOffering.getLaboratoryDay();
				listModel[i][3] = courseOffering.getLaboratoryTime();
				listModel[i][4] = courseOffering.getLaboratoryRoom();
				listModel[i][5] = courseOffering.getLaboratoryInstructor();
			}
			else if(courseOffering.getRecitationDay() != null && courseOffering.getRecitationDay().length() != 0){
				listModel[i][2] = courseOffering.getRecitationDay();
				listModel[i][3] = courseOffering.getRecitationTime();
				listModel[i][4] = courseOffering.getRecitationRoom();
				listModel[i][5] = courseOffering.getRecitationInstructor();
			}
			else{
				listModel[i][2] = courseOffering.getLectureDay();
				listModel[i][3] = courseOffering.getLectureTime();
				listModel[i][4] = courseOffering.getLectureRoom();
				listModel[i][5] = courseOffering.getLectureInstructor();
			}
			listModel[i][6] = courseOffering.getStudentCount().toString();
		}
		
		ListModel strset = new SimpleListModel(listModel);
		contents_win.getFellow("course_offering_g").setModel(strset);
		contents_win.getFellow("course_offering_g").setRowRenderer(new CourseOfferingRenderer());
		
	}catch(Exception e){}
}


/* [start]	automatically updates the 'to' value of academic year based on the
			current 'from' value of the academic year */
private void updateAY(){
	try{
		year2.value = (Integer.parseInt(event.value) + 1).toString();
	}catch(Exception e) {year1.value = null; year2.value = null;}
}
/* [end] */